local _, GrifonOvaleScripts = ...

GrifonOvaleScripts.script.PALADIN.Attilio = {
	desc = "[5.4] Attilio: Retribution",
	code =
[[

#Talents.
Define(TalentSpeedOfLight 1)
Define(TalentLongArmOfTheLaw 2)
Define(TalentPursuitOfJustice 3)
Define(TalentFistOfJustice 4)
Define(TalentRepentance 5)
Define(TalentEvilIsAPointOfView 6)
Define(TalentSelflessHealer 7)
Define(TalentEternalFlame 8)
Define(TalentSacredShield 9)
Define(TalentHandOfPurity 10)
Define(TalentUnbreakableSpirit 11)
Define(TalentClemency 12)
Define(TalentHolyAvenger 13)
Define(TalentSanctifiedWrath 14)
Define(TalentDivinePurpose 15)
Define(TalentHolyPrism 16)
Define(TalentLightsHammer 17)
Define(TalentExecutionSentence 18)

#Glyphs - Major.
Define(GlyphAvengingWrath 54927)
Define(GlyphBattleHealer 119477)
Define(GlyphBlessedLife 54943)
Define(GlyphBlindingLight 54934)
Define(GlyphBurdenOfGuilt 54931)
Define(GlyphDevotionAura 146955)
Define(GlyphDivineProtection 54924)
Define(GlyphDivineShield 146956)
Define(GlyphDivinity 54939)
Define(GlyphDoubleJeopardy 54922)
Define(GlyphFlashOfLight 57955)
Define(GlyphHammerOfTheRighteous 63219)
Define(GlyphHandOfSacrifice 146957)
Define(GlyphHarshWords 54938)
Define(GlyphImmediateTruth 56416)
Define(GlyphProtectorOfTheInnocent 93466)
Define(GlyphWordOfGlory 54936)

#Glyphs - Minor.
Define(GlyphBladedJudgment 115934)
Define(GlyphContemplation 125043)
Define(GlyphExorcist 146958)
Define(GlyphFallingAvenger 115931)
Define(GlyphFireFromTheHeavens 57954)
Define(GlyphLuminousCharger 89401)
Define(GlyphPillarOfLight 146959)
Define(GlyphRighteousRetreat 115933)
Define(GlyphSealOfBlood 57947)
Define(GlyphMountedKing 57958)
Define(GlyphWingedVengeance 57979)

#Glyphs - Protection.
Define(GlyphAlabasterShield 63222)
Define(GlyphConsecration 54928)
Define(GlyphDazingShield 56414)
Define(GlyphFinalWrath 54935)
Define(GlyphFocusedShield 54930)
Define(GlyphHolyWrath 54923)
Define(GlyphFocusedWrath 115738)

#Glyphs - Retribution.
Define(GlyphDivineStorm 63220)
Define(GlyphInquisition 63225)
Define(GlyphMassExorcism 122028)
Define(GlyphTemplarsVerdict 54926)

#Passives.
Define(Parry 82242)
Define(Supplication 31868)
Define(HeartOfTheCrusader 32223)
Define(SanctityOfBattle 25956)
Define(BoundlessConviction 115675)

#Passives - Protection.
Define(GuardedByTheLight 53592)
Define(Vengeance 84839)
Define(JudgmentsOfTheWise 105424)
Define(GrandCrusader 85043)
Define(PlateSpecializationProtection 86102)
Define(Sanctuary 105805)
Define(MasteryDivineBulwark 76671)

#Passives - Retribution.
Define(SwordOfLight 53503)
Define(JudgmentsOfTheBold 111529)
Define(PlateSpecializationRetribution 86539)
Define(TheArtOfWar 87138)
Define(Absolve 140333)
Define(MasteryHandOfLight 76672)

#Passives - Talents.
Define(LongArmOfTheLaw 87172)
Define(PursuitOfJustice 26023)
Define(FistOfJustice 105593)
Define(EvilIsAPointOfView 110301)
Define(SelflessHealer 85804)
Define(EternalFlame 114163)
Define(UnbreakableSpirit 114154)
Define(Clemency 105622)
Define(SanctifiedWrath 53376)
Define(DivinePurpose 86172)

#Abilities.
Define(CrusaderStrike 35395)
Define(Symbiosis 110501)
Define(SealOfCommand 105361)
Define(Judgment 20271)
Define(HammerOfJustice 853)
Define(WordOfGlory 85673)
Define(RighteousFury 25780)
Define(Redemption 7328)
Define(FlashOfLight 19750)
Define(Reckoning 62124)
Define(LayOnHands 633)
Define(DivineShield 642)
Define(Cleanse 4987)
Define(HammerOfTheRighteous 53595)
Define(SealOfTruth 31801)
Define(DivineProtection 498)
Define(BlessingOfKings 20217)  
Define(SealOfInsight 20165)
Define(Rebuke 96231)
Define(HammerOfWrath 24275)
Define(SealOfRighteousness 20154)
Define(TurnEvil 10326)
Define(HandOfProtection 1022)
Define(HandOfFreedom 1044)
Define(DevotionAura 31821)
Define(HandOfSalvation 1038)
Define(AvengingWrath 31884)
Define(HandOfSacrifice 6940)
Define(BlessingOfMight 19740)
Define(BlindingLight 115750)

#Abilities - Protection.
Define(AvengersShield 31935)
Define(HolyWrath 119072)
Define(Consecration 26573)
Define(ShieldOfTheRighteous 53600)
Define(ArdentDefender 31850)
Define(GuardianOfAncientKingsProtection 86659)

#Abilities - Retribution.
Define(TemplarsVerdict 85256)
Define(DivineStorm 53385)
Define(Exorcism 879)
Define(Emancipate 121783)
Define(SealOfJustice 20164)
Define(GuardianOfAncientKingsRetribution 86698)
Define(Inquisition 84963)

#Abilities - Talents.
Define(SpeedOfLight 85499)
Define(Repentance 20066)
Define(SacredShield 20925)
Define(HandOfPurity 114039)
Define(HolyAvenger 105809)
Define(HolyPrism 114165)
Define(LightsHammer 114158)
Define(ExecutionSentence 114157)

#Abilities - Glyphs.
Define(Contemplation 121183)
Define(RangedConsecration 116467)
Define(MassExorcism 122032)

#Abilities - Guild Perks & Battle Pets.
Define(MobileBanking 83958)
Define(MassResurrection 83968)
Define(ReviveBattlePets 125439)

#Abilities - Racial Mounts.
Define(SummonWarhorse 13819)
Define(SummonThalassianWarhorse 34769)
Define(SummonExarchsElekk 73629)
Define(SummonSunwalkerKodo 69820)
Define(SummonCharger 23214)
Define(SummonThalassianCharger 34767)
Define(SummonGreatExarchsElekk 73630)
Define(SummonGreatSunwalkerKodo 69826)

#Debuffs.
Define(Forbearance 25771)
Define(WeakenedBlows 115798)
Define(PhysicalVulnerability 81326)
Define(DebuffSealOfTruth 31803)
Define(DebuffBlindingLight 105421)
Define(DebuffConsecration 81298)

#Debuffs - Glyphs & Talents.
Define(DebuffBurdenOfGuilt 115752)
Define(DebuffDazingShield 63529)
Define(DebuffGlyphBlindingLight 115752)
Define(DebuffEvilIsAPointOfView 145067)
Define(DebuffExecutionSentence 114916)

#Buffs.
Define(BuffSupplication 94686)
Define(BuffShieldOfTheRighteous 132403)
Define(BuffBastionOfGlory 114637)
Define(BuffGrandCrusader 85416)
Define(BuffVengeance 132365)
Define(BuffBarkskin 113075)

#Buffs - Glyphs.
Define(BuffAvengingWrath 115547)
Define(BuffDoubleJeopardy 121027)
Define(BuffFlashOfLight 54957)
Define(BuffWordOfGlory 115522)
Define(BuffAlabasterShield 121467)
Define(BuffTemplarsVerdict 115668)

#Buffs - Talents.
Define(BuffLongArmOfTheLaw 87173)
Define(BuffPursuitOfJustice 114695)
Define(BuffSelflessHealer 114250)
Define(BuffSacredShield 65148)
Define(BuffSanctifiedWrath 114232)
Define(BuffDivinePurpose 90174)
Define(BuffExecutionSentence 114917)

#Buffs - Other classes.
Define(BuffSymbiosis 110484)
Define(GraceOfAir 116956)
Define(RoarOfCourage 93435)
Define(SpiritBeastBlessing 128997)
Define(MarkOfTheWild 1126)
Define(LegacyOfTheEmperor 117666)
Define(EmbraceOfTheShaleSpider 90363)

#Buffs - Items.
Define(BuffOvergrownLilypad 129716)
Define(BuffCrystalOfInsanity 127230)
Define(BuffKafaPress 125282)
Define(Fortitude 137593)
Define(Capacitance 137596)
Define(FlurryOfXuen 146194)
Define(DivineCrusader 144595)

#Buffs - Consumables.
Define(BuffLifeSpirit 130649)
Define(BuffPotionOfTheMountains 105698)
Define(BuffPotionOfMoguPower 105706)
Define(BuffFlaskOfTheEarth 105694)
Define(BuffFlaskOfWintersBite 105696)

#Items.
Define(OvergrownLilypad 86580)
Define(CrystalOfInsanity 86569)
Define(KafaPress 86125)
Define(Fortitude 137593)
Define(Capacitance 137596)
Define(EnduranceOfNiuzao 148010)
Define(FlurryOfXuen 146194)

#Items - Consumables.
Define(Healthstone 5512)
Define(LifeSpirit 89640)
Define(MasterHealingPotion 76097)
Define(PotionOfTheMountains 76090)
Define(PotionOfMoguPower 76095)
Define(FlaskOfTheEarth 76087)
Define(FlaskOfWintersBite 76088)

#Buffing.
AddIcon mastery=2 help=buff nocd=3 {

  #Seal of Insight.
  if Stance(0) {
    Spell(SealOfInsight usable=1)
    Spell(SealOfTruth usable=1) #For lower levels.
    Spell(SealOfCommand usable=1) #For lower levels.
  }

  #Blessing of Might.
  if BuffExpires(BlessingOfMight 120 any=1) and BuffExpires(GraceOfAir any=1) and BuffExpires(RoarOfCourage any=1) and BuffExpires(SpiritBeastBlessing any=1) and BuffExpires(BlessingOfKings) {
    Spell(BlessingOfMight usable=1)
  }

  #Blessing of Kings.
  if BuffExpires(BlessingOfKings 120 any=1) and BuffExpires(MarkOfTheWild 120 any=1) and BuffExpires(LegacyOfTheEmperor 120 any=1) and BuffExpires(EmbraceOfTheShaleSpider any=1) and BuffExpires(BlessingOfMight) {
    Spell(BlessingOfKings usable=1)
  }

  #Blessing of Might.
  if BuffExpires(BlessingOfMight 120 any=1) and BuffExpires(BlessingOfKings) {
    Spell(BlessingOfMight usable=1)
  }

  #Blessing of Kings.
  if BuffExpires(BlessingOfKings 120 any=1) and BuffExpires(MarkOfTheWild 120 any=1) and BuffExpires(LegacyOfTheEmperor 120 any=1) and BuffExpires(BlessingOfMight) {
    Spell(BlessingOfKings usable=1)
  }

  #Flask of the Earth.
  if BuffPresent(BuffFlaskOfTheEarth) and BuffExpires(BuffFlaskOfTheEarth 120) {
    Item(FlaskOfTheEarth usable=1)
  }

  #Flask of Winter's Bite.
  if BuffPresent(BuffFlaskOfWintersBite) and BuffExpires(BuffFlaskOfWintersBite 120) {
    Item(FlaskOfWintersBite usable=1)
  }

  #Crystal of Insanity.
  if BuffExpires(BuffCrystalOfInsanity 120) and BuffExpires(BuffFlaskOfTheEarth) and BuffExpires(BuffFlaskOfWintersBite) {
    Item(CrystalOfInsanity usable=1)
  }

  #Righteous Fury.
  if BuffExpires(RighteousFury) {
    Spell(RighteousFury usable=1)
  }

  #Seal of Insight.
  unless Stance(3) {
    Spell(SealOfInsight usable=1)
  }
}
AddIcon mastery=3 help=buff nocd=3 {

  #Seal of Truth.
  if Stance(0) {
    Spell(SealOfTruth usable=1)
    Spell(SealOfCommand usable=1) #For lower levels.
  }

  #Blessing of Kings.
  if BuffExpires(BlessingOfKings 120 any=1) and BuffExpires(MarkOfTheWild 120 any=1) and BuffExpires(LegacyOfTheEmperor 120 any=1) and BuffExpires(EmbraceOfTheShaleSpider any=1) and BuffExpires(BlessingOfMight) {
    Spell(BlessingOfKings usable=1)
  }

  #Blessing of Might.
  if BuffExpires(BlessingOfMight 120 any=1) and BuffExpires(GraceOfAir any=1) and BuffExpires(RoarOfCourage any=1) and BuffExpires(SpiritBeastBlessing any=1) and BuffExpires(BlessingOfKings) {
    Spell(BlessingOfMight usable=1)
  }

  #Blessing of Kings.
  if BuffExpires(BlessingOfKings 120 any=1) and BuffExpires(MarkOfTheWild 120 any=1) and BuffExpires(LegacyOfTheEmperor 120 any=1) and BuffExpires(BlessingOfMight) {
    Spell(BlessingOfKings usable=1)
  }

  #Blessing of Might.
  if BuffExpires(BlessingOfMight 120 any=1) and BuffExpires(BlessingOfKings) {
    Spell(BlessingOfMight usable=1)
  }

  #Flask of the Earth.
  if BuffPresent(BuffFlaskOfTheEarth) and BuffExpires(BuffFlaskOfTheEarth 120) {
    Item(FlaskOfTheEarth usable=1)
  }

  #Flask of Winter's Bite.
  if BuffPresent(BuffFlaskOfWintersBite) and BuffExpires(BuffFlaskOfWintersBite 120) {
    Item(FlaskOfWintersBite usable=1)
  }

  #Crystal of Insanity.
  if BuffExpires(BuffCrystalOfInsanity 120) and BuffExpires(BuffFlaskOfTheEarth) and BuffExpires(BuffFlaskOfWintersBite) {
    Item(CrystalOfInsanity usable=1)
  }

  #Cancelaura Righteous Fury.
  if BuffPresent(RighteousFury) {
    Spell(HeartOfTheCrusader)
  }

  #Seal of Truth.
  unless Stance(1) {
    Spell(SealOfTruth usable=1)
  }
}

#Interrupts and selfheals.
AddIcon mastery=2 help=cd nocd=3 {

  #Rebuke.
  if target.IsInterruptible() and target.IsFriend(no) and target.InRange(Rebuke) {
    Spell(Rebuke usable=1)
  }

  #Avenger's Shield.
  if target.IsInterruptible() and target.IsFriend(no) {
    Spell(AvengersShield usable=1)
  }

  #Flash of Light with Selfless Healer.
  if HealthPercent() < 50 and BuffStacks(SelflessHealer) >= 3 and target.IsFriend(no) {
    Spell(FlashOfLight usable=1)
  }

  #Eternal Flame when the buff expired.
  if HealthPercent() < 50 and TalentPoints(TalentEternalFlame) and BuffExpires(EternalFlame) and target.IsFriend(no) {
    if HolyPower() >= 3 or BuffPresent(DivinePurpose) {
      Spell(WordOfGlory usable=1)
    }
    if BuffStacks(BuffBastionOfGlory) >= 3 and ArmorSetParts(T16_tank) >= 4 {
      Spell(WordOfGlory usable=1)
    }
  }

  #Healthstone.
  if HealthPercent() < 50 and InCombat() {
    Item(Healthstone usable=1)
  }

  #Word of Glory.
  if HealthPercent() < 50 and target.IsFriend(no) {
    if HolyPower() >= 3 or BuffPresent(DivinePurpose) {
      Spell(WordOfGlory usable=1)
    }
    if BuffStacks(BuffBastionOfGlory) >= 3 and ArmorSetParts(T16_tank) >= 4 {
      Spell(WordOfGlory usable=1)
    }
  }

  #Lay on Hands without Forbearance.
  if HealthPercent() < 50 and BuffExpires(Forbearance) and target.IsFriend(no) and InCombat() {
    Spell(LayOnHands usable=1)
  }

  #Ardent Defender.
  if HealthPercent() < 50 and InCombat() {
    Spell(ArdentDefender usable=1)
  }

  #Healing Potion.
  if HealthPercent() < 50 and InCombat() {
    Item(MasterHealingPotion usable=1)
  }

  #Life Spirit.
  if HealthPercent() < 50 and InCombat() {
    Item(LifeSpirit usable=1)
  }

  #Cleanse.
  if BuffPresent(Disease any=1) or BuffPresent(Poison any=1) {
    if target.IsFriend(no) {
      Spell(Cleanse usable=1)
    }
  }
}
AddIcon mastery=3 help=cd nocd=3 {

  #Rebuke.
  if target.IsInterruptible() and target.IsFriend(no) and target.InRange(Rebuke) {
    Spell(Rebuke usable=1)
  }

  #Flash of Light with Selfless Healer.
  if HealthPercent() < 50 and BuffStacks(SelflessHealer) >= 3 and target.IsFriend(no) {
    Spell(FlashOfLight usable=1)
  }

  #Eternal Flame when the buff expired.
  if HealthPercent() < 50 and TalentPoints(TalentEternalFlame) and BuffExpires(EternalFlame) and target.IsFriend(no) {
    if HolyPower() >= 3 or BuffPresent(DivinePurpose) {
      Spell(WordOfGlory usable=1)
    }
  }

  #Healthstone.
  if HealthPercent() < 50 and InCombat() {
    Item(Healthstone usable=1)
  }

  #Word of Glory.
  if HealthPercent() < 50 and target.IsFriend(no) {
    if HolyPower() >= 3 or BuffPresent(DivinePurpose) {
      Spell(WordOfGlory usable=1)
    }
  }

  #Lay on Hands without Forbearance.
  if HealthPercent() < 50 and BuffExpires(Forbearance) and target.IsFriend(no) and InCombat() {
    Spell(LayOnHands usable=1)
  }

  #Healing Potion.
  if HealthPercent() < 50 and InCombat() {
    Item(MasterHealingPotion usable=1)
  }

  #Life Spirit.
  if HealthPercent() < 50 and InCombat() {
    Item(LifeSpirit usable=1)
  }

  #Cleanse.
  if BuffPresent(Disease any=1) or BuffPresent(Poison any=1) {
    if target.IsFriend(no) {
      Spell(Cleanse usable=1)
    }
  }
}

#Single Target Rotation.
AddIcon mastery=2 help=main nocd=3 {

  #Eternal Flame when wounded and the buff expired.
  if TalentPoints(TalentEternalFlame) and target.IsFriend(no) and HealthPercent() < 50 and BuffExpires(EternalFlame) {
    if HolyPower() >= 3 or BuffPresent(DivinePurpose) {
      Spell(WordOfGlory usable=1)
    }
    if BuffStacks(BuffBastionOfGlory) >= 3 and ArmorSetParts(T16_tank) >= 4 {
      Spell(WordOfGlory usable=1)
    }
  }

  #Eternal Flame with maximum Bastion of Glory when Bastion of Glory is about to run out.
  if TalentPoints(TalentEternalFlame) and target.IsFriend(no) and BuffStacks(BuffBastionOfGlory) >= 5 and BuffExpires(BuffBastionOfGlory 1.5) {
    if HolyPower() >= 3 or BuffPresent(DivinePurpose) or ArmorSetParts(T16_tank) >= 4 {
      Spell(WordOfGlory usable=1)
    }
  }

  #Eternal Flame with maximum Bastion of Glory when Divine Purpose is about to run out.
  if TalentPoints(TalentEternalFlame) and target.IsFriend(no) and BuffStacks(BuffBastionOfGlory) >= 5 and BuffPresent(DivinePurpose) and BuffExpires(DivinePurpose 1.5) {
    Spell(WordOfGlory usable=1)
  }

  #Eternal Flame with maximum Bastion of Glory when maximum holy power is about to be exceeded.
  if TalentPoints(TalentEternalFlame) and target.IsFriend(no) and BuffStacks(BuffBastionOfGlory) >= 5 and HolyPower() >= 3 {
    if SpellKnown(BoundlessConviction no) or HolyPower() >= 5 or BuffPresent(HolyAvenger) {
      if SpellCooldown(CrusaderStrike) < GCD() or SpellCooldown(Judgment) < GCD() or BuffPresent(BuffGrandCrusader) {
        Spell(WordOfGlory usable=1)
      }
    }
    if HolyPower() >= 4 and BuffPresent(SanctifiedWrath) and SpellCooldown(Judgment) < GCD() {
      Spell(WordOfGlory usable=1)
    }
  }

  #Self buffs and heals.
  if InCombat(no) and target.IsFriend(no) {

    #Cleanse.
    if BuffPresent(Disease any=1) or BuffPresent(Poison any=1) {
      Spell(Cleanse usable=1)
    }

    #Flash of Light.
    if HealthPercent() < 90 {
      Spell(FlashOfLight usable=1)
    }

    #Sacred Shield.
    if TalentPoints(TalentSacredShield) and target.Exists() {
      Spell(SacredShield usable=1)
    }
  }

  #Friend buffs and heals.
  if InCombat(no) and target.Exists() and target.IsFriend() {

    #Redemption.
    if target.HealthPercent() == 0 {
      Spell(Redemption usable=1)
    }

    #Cleanse.
    if target.BuffPresent(Disease any=1) or target.BuffPresent(Poison any=1) {
      Spell(Cleanse usable=1)
    }

    #Flash of Light.
    if target.HealthPercent() < 90 {
      Spell(FlashOfLight usable=1)
    }
  }

  #Melee attacks.
  if target.Exists() and target.IsFriend(no) and target.InRange(CrusaderStrike) {

    #Shield of the Righteous when Bastion of Glory is about to run out.
    if BuffPresent(BuffBastionOfGlory) and BuffExpires(BuffBastionOfGlory 1.5) {
      Spell(ShieldOfTheRighteous usable=1)
    }

    #Shield of the Righteous when Divine Purpose is about to run out.
    if BuffPresent(DivinePurpose) and BuffExpires(DivinePurpose 1.5) {
      Spell(ShieldOfTheRighteous usable=1)
    }

    #Shield of the Righteous when maximum holy power is about to be exceeded.
    if SpellKnown(BoundlessConviction no) or HolyPower() >= 5 or BuffPresent(HolyAvenger) {
      if SpellCooldown(CrusaderStrike) < GCD() or SpellCooldown(Judgment) < GCD() or BuffPresent(BuffGrandCrusader) {
        Spell(ShieldOfTheRighteous usable=1)
      }
    }
    if HolyPower() >= 4 and BuffPresent(SanctifiedWrath) and SpellCooldown(Judgment) < GCD() {
      Spell(ShieldOfTheRighteous usable=1)
    }

    #Judgment with Sanctified Wrath.
    if BuffPresent(SanctifiedWrath) {
      Spell(Judgment usable=1)
    }

    #Crusader Strike unless Judgment with Sanctified Wrath is almost ready.
    if BuffExpires(SanctifiedWrath) or SpellUsable(Judgment no) or SpellCooldown(Judgment) > 0.25 {
      Spell(CrusaderStrike usable=1)
    }

    #Judgment unless Crusader Strike is almost ready.
    if SpellUsable(CrusaderStrike no) or SpellCooldown(CrusaderStrike) > 0.25 {
      Spell(Judgment usable=1)
    }

    #Prevent other abilities when Crusader Strike or Judgment is almost ready.
    if BuffPresent(SanctifiedWrath) or SpellUsable(CrusaderStrike no) or SpellCooldown(CrusaderStrike) > 0.25 {
      if BuffPresent(SanctifiedWrath) or SpellUsable(Judgment no) or SpellCooldown(Judgment) > 0.25 or SpellCooldown(CrusaderStrike) - SpellCooldown(Judgment) < 0.25 {
        if BuffExpires(SanctifiedWrath) or SpellUsable(Judgment no) or SpellCooldown(Judgment) > 0.25 {
          if BuffExpires(SanctifiedWrath) or SpellUsable(CrusaderStrike no) or SpellCooldown(CrusaderStrike) > 0.25 or SpellCooldown(Judgment) - SpellCooldown(CrusaderStrike) < 0.25 {

            #Avenger's Shield with Grand Crusader.
            if BuffPresent(BuffGrandCrusader) {
              Spell(AvengersShield usable=1)
            }

            #Sacred Shield when expiring.
            if TalentPoints(TalentSacredShield) and BuffExpires(SacredShield 5) {
              Spell(SacredShield usable=1)
            }

            #Avenger's Shield.
            Spell(AvengersShield usable=1)

            #Holy Wrath with final wrath.
            if Glyph(GlyphFinalWrath) and target.HealthPercent() < 20 {
              Spell(HolyWrath usable=1)
            }

            #Holy Wrath.
            Spell(HolyWrath usable=1)

            #Execution Sentence in execution range.
            if TalentPoints(TalentExecutionSentence) and target.HealthPercent() < 20 {
              Spell(ExecutionSentence usable=1)
            }

            #Execution Sentence.
            if TalentPoints(TalentExecutionSentence) {
              Spell(ExecutionSentence usable=1)
            }

            #Light's Hammer in execution range.
            if TalentPoints(TalentLightsHammer) and target.HealthPercent() < 20 {
              Spell(LightsHammer usable=1)
            }

            #Light's Hammer.
            if TalentPoints(TalentLightsHammer) {
              Spell(LightsHammer usable=1)
            }

            #Hammer of Wrath.
            Spell(HammerOfWrath usable=1)

            #Normal Consecration.
            if Glyph(GlyphConsecration no) {
              Spell(Consecration usable=1)
            }

            #Ranged Consecration.
            if Glyph(GlyphConsecration) {
              Spell(RangedConsecration usable=1)
            }

            #Holy Prism in execution range.
            if TalentPoints(TalentHolyPrism) and target.HealthPercent() < 20 {
              Spell(HolyPrism usable=1)
            }

            #Holy Prism.
            if TalentPoints(TalentHolyPrism) {
              Spell(HolyPrism usable=1)
            }
          }
        }
      }
    }
  }

  #Ranged attacks.
  if target.Exists() and target.IsFriend(no) and target.InRange(CrusaderStrike no) {

    #Judgment.
    Spell(Judgment usable=1)

    #Prevent other abilities when Judgment is almost ready.
    if SpellUsable(Judgment no) or SpellCooldown(Judgment) > 0.25 {

      #Avenger's Shield with Grand Crusader.
      if BuffPresent(BuffGrandCrusader) {
        Spell(AvengersShield usable=1)
      }

      #Sacred Shield when expiring.
      if TalentPoints(TalentSacredShield) and BuffExpires(SacredShield 5) {
        Spell(SacredShield usable=1)
      }

      #Avenger's Shield.
      Spell(AvengersShield usable=1)

      #Execution Sentence in execution range.
      if TalentPoints(TalentExecutionSentence) and target.HealthPercent() < 20 {
        Spell(ExecutionSentence usable=1)
      }

      #Execution Sentence.
      if TalentPoints(TalentExecutionSentence) {
        Spell(ExecutionSentence usable=1)
      }

      #Light's Hammer in execution range.
      if TalentPoints(TalentLightsHammer) and target.HealthPercent() < 20 {
        Spell(LightsHammer usable=1)
      }

      #Light's Hammer.
      if TalentPoints(TalentLightsHammer) {
        Spell(LightsHammer usable=1)
      }

      #Hammer of Wrath.
      Spell(HammerOfWrath usable=1)

      #Normal Consecration.
      if Glyph(GlyphConsecration no) {
        Spell(Consecration usable=1)
      }

      #Ranged Consecration.
      if Glyph(GlyphConsecration) {
        Spell(RangedConsecration usable=1)
      }
    }
  }

  #Self buffs and heals.
  if target.IsFriend(no) {

    #Cleanse.
    if BuffPresent(Disease any=1) or BuffPresent(Poison any=1) {
      Spell(Cleanse usable=1)
    }

    #Sacred Shield.
    if TalentPoints(TalentSacredShield) and InCombat() {
      Spell(SacredShield usable=1)
    }
  }
}
AddIcon mastery=3 help=main nocd=3 {

  #Inquisition when expiring.
  if BuffExpires(Inquisition 2) {
    if HolyPower() >= 3 or BuffPresent(DivinePurpose) {
      Spell(Inquisition usable=1)
    }
  }

  #Self buffs and heals.
  if InCombat(no) and target.IsFriend(no) {

    #Cleanse.
    if BuffPresent(Disease any=1) or BuffPresent(Poison any=1) {
      Spell(Cleanse usable=1)
    }

    #Flash of Light.
    if HealthPercent() < 90 {
      Spell(FlashOfLight usable=1)
    }

    #Sacred Shield.
    if TalentPoints(TalentSacredShield) and target.Exists() {
      Spell(SacredShield usable=1)
    }
  }

  #Friend buffs and heals.
  if target.Exists() and target.IsFriend() {

    #Redemption.
    if target.HealthPercent() == 0 {
      Spell(Redemption usable=1)
    }

    #Cleanse.
    if target.BuffPresent(Disease any=1) or target.BuffPresent(Poison any=1) {
      Spell(Cleanse usable=1)
    }

    #Flash of Light.
    if target.HealthPercent() < 90 {
      Spell(FlashOfLight usable=1)
    }
  }

  #Melee attacks.
  if target.Exists() and target.IsFriend(no) and target.InRange(CrusaderStrike) {

    #Holy Prism with Inquisition.
    if TalentPoints(TalentHolyPrism) and BuffPresent(Inquisition) {
      Spell(HolyPrism usable=1)
    }

    #Light's Hammer with Inquisition.
    if TalentPoints(TalentLightsHammer) and BuffPresent(Inquisition) {
      Spell(LightsHammer usable=1)
    }

    #Execution Sentence with Inquisition.
    if TalentPoints(TalentExecutionSentence) and BuffPresent(Inquisition) {
      Spell(ExecutionSentence usable=1)
    }

    #Divine Storm with Divine Crusader when Divine Purpose is about to run out.
    if BuffPresent(DivinePurpose) and BuffExpires(DivinePurpose 3) {
      if BuffPresent(DivineCrusader) {
        Spell(DivineStorm usable=1)
      }

      #Templar's Verdict when Divine Purpose is about to run out.
      Spell(TemplarsVerdict usable=1)
    }

    #Divine Storm with Divine Crusader when maximum holy power is about to be exceeded.
    if SpellKnown(BoundlessConviction no) or HolyPower() >= 5 or BuffPresent(HolyAvenger) {
      if BuffPresent(DivineCrusader) {
        Spell(DivineStorm usable=1)
      }

      #Templar's Verdict when maximum holy power is about to be exceeded.
      Spell(TemplarsVerdict usable=1)
    }

    #Hammer of Wrath.
    Spell(HammerOfWrath usable=1)

    #Prevent other abilities when Hammer of Wrath is almost ready.
    if SpellUsable(HammerOfWrath no) or SpellCooldown(HammerOfWrath) > 0.25 {

      #Divine Storm with Divine Crusader and Sanctified Wrath.
      if BuffPresent(DivineCrusader) and BuffPresent(SanctifiedWrath) {
        Spell(DivineStorm usable=1)
      }

      #Templar's Verdict with Sanctified Wrath.
      if BuffPresent(SanctifiedWrath) {
        Spell(TemplarsVerdict usable=1)
      }

      #Crusader Strike.
      Spell(CrusaderStrike usable=1)

      #Divine Storm with Divine Crusader.
      if BuffPresent(DivineCrusader) {
        Spell(DivineStorm usable=1)
      }

      #Judgment.
      Spell(Judgment usable=1)

      #Normal Exorcism.
      if Glyph(GlyphMassExorcism no) {
        Spell(Exorcism usable=1)
      }

      #Mass Exorcism.
      if Glyph(GlyphMassExorcism) {
        Spell(MassExorcism usable=1)
      }

      #Templar's Verdict.
      Spell(TemplarsVerdict usable=1)
    }
  }

  #Ranged attacks.
  if target.Exists() and target.IsFriend(no) and target.InRange(CrusaderStrike no) {

    #Judgment when Censure is about to run out.
    if SpellKnown(SealOfTruth) and Stance(1) and BuffPresent(Censure) and BuffExpires(Censure 5) {
      Spell(Judgment usable=1)
    }

    #Light's Hammer with Inquisition.
    if TalentPoints(TalentLightsHammer) and BuffPresent(Inquisition) {
      Spell(LightsHammer usable=1)
    }

    #Execution Sentence with Inquisition.
    if TalentPoints(TalentExecutionSentence) and BuffPresent(Inquisition) {
      Spell(ExecutionSentence usable=1)
    }

    #Hammer of Wrath.
    Spell(HammerOfWrath usable=1)

    #Prevent other abilities when Hammer of Wrath is almost ready.
    if SpellUsable(HammerOfWrath no) or SpellCooldown(HammerOfWrath) > 0.25 {

      #Judgment to build holy power or Censure stacks.
      if HolyPower() < 3 or target.BuffStacks(Censure) < 5 {
        Spell(Judgment usable=1)
      }

      #Normal Exorcism to build holy power.
      if HolyPower() < 3 and Glyph(GlyphMassExorcism no) {
        Spell(Exorcism usable=1)
      }

      #Wrath.
      if BuffPresent(BuffSymbiosis) or BuffPresent(BuffOvergrownLilypad) {
        spell(Symbiosis usable=1)
      }

      #Harsh Words with 5 holy power.
      if HolyPower() >= 5 and Glyph(GlyphHarshWords) {
        Spell(WordOfGlory usable=1)
      }

      #Judgment.
      Spell(Judgment usable=1)

      #Normal Exorcism.
      if Glyph(GlyphMassExorcism no) {
        Spell(Exorcism usable=1)
      }
    }
  }

  #Self buffs and heals.
  if target.IsFriend(no) {

    #Cleanse.
    if BuffPresent(Disease any=1) or BuffPresent(Poison any=1) {
      Spell(Cleanse usable=1 priority=1)
    }

    #Sacred Shield.
    if TalentPoints(TalentSacredShield) and InCombat() {
      Spell(SacredShield usable=1 priority=1)
    }
  }
}

#Multi Target Rotation.
AddIcon mastery=2 help=aoe nocd=3 {

  #Eternal Flame when wounded and the buff expired.
  if TalentPoints(TalentEternalFlame) and target.IsFriend(no) and HealthPercent() < 50 and BuffExpires(EternalFlame) {
    if HolyPower() >= 3 or BuffPresent(DivinePurpose) {
      Spell(WordOfGlory usable=1)
    }
    if BuffStacks(BuffBastionOfGlory) >= 3 and ArmorSetParts(T16_tank) >= 4 {
      Spell(WordOfGlory usable=1)
    }
  }

  #Eternal Flame with maximum Bastion of Glory when Bastion of Glory is about to run out.
  if TalentPoints(TalentEternalFlame) and target.IsFriend(no) and BuffStacks(BuffBastionOfGlory) >= 5 and BuffExpires(BuffBastionOfGlory 1.5) {
    if HolyPower() >= 3 or BuffPresent(DivinePurpose) or ArmorSetParts(T16_tank) >= 4 {
      Spell(WordOfGlory usable=1)
    }
  }

  #Eternal Flame with maximum Bastion of Glory when Divine Purpose is about to run out.
  if TalentPoints(TalentEternalFlame) and target.IsFriend(no) and BuffStacks(BuffBastionOfGlory) >= 5 and BuffPresent(DivinePurpose) and BuffExpires(DivinePurpose 1.5) {
    Spell(WordOfGlory usable=1)
  }

  #Eternal Flame with maximum Bastion of Glory when maximum holy power is about to be exceeded.
  if TalentPoints(TalentEternalFlame) and target.IsFriend(no) and BuffStacks(BuffBastionOfGlory) >= 5 and HolyPower() >= 3 {
    if SpellKnown(BoundlessConviction no) or HolyPower() >= 5 or BuffPresent(HolyAvenger) {
      if SpellCooldown(CrusaderStrike) < GCD() or SpellCooldown(Judgment) < GCD() or BuffPresent(BuffGrandCrusader) {
        Spell(WordOfGlory usable=1)
      }
    }
    if HolyPower() >= 4 and BuffPresent(SanctifiedWrath) and SpellCooldown(Judgment) < GCD() {
      Spell(WordOfGlory usable=1)
    }
  }

  #Self buffs and heals.
  if InCombat(no) and target.IsFriend(no) {

    #Cleanse.
    if BuffPresent(Disease any=1) or BuffPresent(Poison any=1) {
      Spell(Cleanse usable=1)
    }

    #Flash of Light.
    if HealthPercent() < 90 {
      Spell(FlashOfLight usable=1)
    }

    #Sacred Shield.
    if TalentPoints(TalentSacredShield) and target.Exists() {
      Spell(SacredShield usable=1)
    }
  }

  #Friend buffs and heals.
  if target.IsFriend() {

    #Redemption.
    if target.HealthPercent() == 0 {
      Spell(Redemption usable=1)
    }

    #Cleanse.
    if target.BuffPresent(Disease any=1) or target.BuffPresent(Poison any=1) {
      Spell(Cleanse usable=1)
    }

    #Flash of Light.
    if target.HealthPercent() < 90 {
      Spell(FlashOfLight usable=1)
    }
  }

  #Melee attacks.
  if target.Exists() and target.IsFriend(no) and target.InRange(CrusaderStrike) {

    #Shield of the Righteous when Bastion of Glory is about to run out.
    if BuffPresent(BuffBastionOfGlory) and BuffExpires(BuffBastionOfGlory 1.5) {
      Spell(ShieldOfTheRighteous usable=1)
    }

    #Shield of the Righteous when Divine Purpose is about to run out.
    if BuffPresent(DivinePurpose) and BuffExpires(DivinePurpose 1.5) {
      Spell(ShieldOfTheRighteous usable=1)
    }

    #Shield of the Righteous when maximum holy power is about to be exceeded.
    if SpellKnown(BoundlessConviction no) or HolyPower() >= 5 or BuffPresent(HolyAvenger) {
      if SpellCooldown(CrusaderStrike) < GCD() or SpellCooldown(Judgment) < GCD() or BuffPresent(BuffGrandCrusader) {
        Spell(ShieldOfTheRighteous usable=1)
      }
    }
    if HolyPower() >= 4 and BuffPresent(SanctifiedWrath) and SpellCooldown(Judgment) < GCD() {
      Spell(ShieldOfTheRighteous usable=1)
    }

    #Avenger's Shield with Grand Crusader.
    if BuffPresent(BuffGrandCrusader) {
      Spell(AvengersShield usable=1)
    }

    #Judgment with Sanctified Wrath.
    if BuffPresent(SanctifiedWrath) {
      Spell(Judgment usable=1)
    }

    #Hammer of the Righteous unless Judgment with Sanctified Wrath is almost ready.
    if BuffExpires(SanctifiedWrath) or SpellUsable(Judgment no) or SpellCooldown(Judgment) > 0.25 {
      Spell(HammerOfTheRighteous usable=1)
      Spell(CrusaderStrike usable=1) #For lower levels.
    }

    #Judgment unless Crusader Strike is almost ready.
    if SpellUsable(CrusaderStrike no) or SpellCooldown(CrusaderStrike) > 0.25 {
      Spell(Judgment usable=1)
    }

    #Prevent other abilities when Crusader Strike or Judgment is almost ready.
    if BuffPresent(SanctifiedWrath) or SpellUsable(CrusaderStrike no) or SpellCooldown(CrusaderStrike) > 0.25 {
      if BuffPresent(SanctifiedWrath) or SpellUsable(Judgment no) or SpellCooldown(Judgment) > 0.25 or SpellCooldown(CrusaderStrike) - SpellCooldown(Judgment) < 0.25 {
        if BuffExpires(SanctifiedWrath) or SpellUsable(Judgment no) or SpellCooldown(Judgment) > 0.25 {
          if BuffExpires(SanctifiedWrath) or SpellUsable(CrusaderStrike no) or SpellCooldown(CrusaderStrike) > 0.25 or SpellCooldown(Judgment) - SpellCooldown(CrusaderStrike) < 0.25 {

            #Sacred Shield when expiring.
            if TalentPoints(TalentSacredShield) and BuffExpires(SacredShield 5) {
              Spell(SacredShield usable=1)
            }

            #Avenger's Shield.
            Spell(AvengersShield usable=1)

            #Light's Hammer in execution range.
            if TalentPoints(TalentLightsHammer) and target.HealthPercent() < 20 {
              Spell(LightsHammer usable=1)
            }

            #Light's Hammer.
            if TalentPoints(TalentLightsHammer) {
              Spell(LightsHammer usable=1)
            }

            #Normal Consecration.
            if Glyph(GlyphConsecration no) {
              Spell(Consecration usable=1)
            }

            #Ranged Consecration.
            if Glyph(GlyphConsecration) {
              Spell(RangedConsecration usable=1)
            }

            #Holy Prism in execution range.
            if TalentPoints(TalentHolyPrism) and target.HealthPercent() < 20 {
              Spell(HolyPrism usable=1)
            }

            #Holy Prism.
            if TalentPoints(TalentHolyPrism) {
              Spell(HolyPrism usable=1)
            }

            #Holy Wrath.
            Spell(HolyWrath usable=1)

            #Execution Sentence in execution range.
            if TalentPoints(TalentExecutionSentence) and target.HealthPercent() < 20 {
              Spell(ExecutionSentence usable=1)
            }

            #Execution Sentence.
            if TalentPoints(TalentExecutionSentence) {
              Spell(ExecutionSentence usable=1)
            }

            #Hammer of Wrath.
            Spell(HammerOfWrath usable=1)
          }
        }
      }
    }
  }

  #Ranged attacks.
  if target.Exists() and target.IsFriend(no) and target.InRange(CrusaderStrike no) {

    #Avenger's Shield with Grand Crusader.
    if BuffPresent(BuffGrandCrusader) {
      Spell(AvengersShield usable=1)
    }

    #Judgment.
    Spell(Judgment usable=1)

    #Prevent other abilities when Judgment is almost ready.
    if SpellUsable(Judgment no) or SpellCooldown(Judgment) > 0.25 {

      #Sacred Shield when expiring.
      if TalentPoints(TalentSacredShield) and BuffExpires(SacredShield 5) {
        Spell(SacredShield usable=1)
      }

      #Avenger's Shield.
      Spell(AvengersShield usable=1)

      #Light's Hammer in execution range.
      if TalentPoints(TalentLightsHammer) and target.HealthPercent() < 20 {
        Spell(LightsHammer usable=1)
      }

      #Light's Hammer.
      if TalentPoints(TalentLightsHammer) {
        Spell(LightsHammer usable=1)
      }

      #Ranged Consecration.
      if Glyph(GlyphConsecration) {
        Spell(RangedConsecration usable=1)
      }

      #Execution Sentence in execution range.
      if TalentPoints(TalentExecutionSentence) and target.HealthPercent() < 20 {
        Spell(ExecutionSentence usable=1)
      }

      #Execution Sentence.
      if TalentPoints(TalentExecutionSentence) {
        Spell(ExecutionSentence usable=1)
      }

      #Hammer of Wrath.
      Spell(HammerOfWrath usable=1)
    }
  }

  #Self buffs and heals.
  if target.IsFriend(no) {

    #Cleanse.
    if BuffPresent(Disease any=1) or BuffPresent(Poison any=1) {
      Spell(Cleanse usable=1)
    }

    #Sacred Shield.
    if TalentPoints(TalentSacredShield) and InCombat() {
      Spell(SacredShield usable=1)
    }
  }
}
AddIcon mastery=3 help=aoe nocd=3 {

  #Inquisition when expiring.
  if BuffExpires(Inquisition 2) {
    if HolyPower() >= 3 or BuffPresent(DivinePurpose) {
      Spell(Inquisition usable=1)
    }
  }

  #Self buffs and heals.
  if InCombat(no) and target.IsFriend(no) {

    #Cleanse.
    if BuffPresent(Disease any=1) or BuffPresent(Poison any=1) {
      Spell(Cleanse usable=1)
    }

    #Flash of Light.
    if HealthPercent() < 90 {
      Spell(FlashOfLight usable=1)
    }

    #Sacred Shield.
    if TalentPoints(TalentSacredShield) and target.Exists() {
      Spell(SacredShield usable=1)
    }
  }

  #Friend buffs and heals.
  if target.IsFriend() {

    #Redemption.
    if target.HealthPercent() == 0 {
      Spell(Redemption usable=1)
    }

    #Cleanse.
    if target.BuffPresent(Disease any=1) or target.BuffPresent(Poison any=1) {
      Spell(Cleanse usable=1)
    }

    #Flash of Light.
    if target.HealthPercent() < 90 {
      Spell(FlashOfLight usable=1)
    }
  }

  #Melee attacks.
  if target.Exists() and target.IsFriend(no) and target.InRange(CrusaderStrike) {

    #Holy Prism with Inquisition.
    if TalentPoints(TalentHolyPrism) and BuffPresent(Inquisition) {
      Spell(HolyPrism usable=1)
    }

    #Light's Hammer with Inquisition.
    if TalentPoints(TalentLightsHammer) and BuffPresent(Inquisition) {
      Spell(LightsHammer usable=1)
    }

    #Execution Sentence with Inquisition.
    if TalentPoints(TalentExecutionSentence) and BuffPresent(Inquisition) {
      Spell(ExecutionSentence usable=1)
    }

    #Divine Storm when Divine Purpose is about to run out.
    if BuffPresent(DivinePurpose) and BuffExpires(DivinePurpose 3) {
      Spell(DivineStorm usable=1)
    }

    #Divine Storm when maximum holy power is about to be exceeded.
    if SpellKnown(BoundlessConviction no) or HolyPower() >= 5 or BuffPresent(HolyAvenger) {
      Spell(DivineStorm usable=1)
      Spell(TemplarsVerdict usable=1) #For lower levels.
    }

    #Hammer of Wrath.
    Spell(HammerOfWrath usable=1)

    #Prevent other abilities when Hammer of Wrath is almost ready.
    if SpellUsable(HammerOfWrath no) or SpellCooldown(HammerOfWrath) > 0.25 {

      #Divine Storm with Sanctified Wrath.
      if BuffPresent(SanctifiedWrath) {
        Spell(DivineStorm usable=1)
      }

      #Hammer of the Righteous.
      Spell(HammerOfTheRighteous usable=1)

      #Mass Exorcism.
      if Glyph(GlyphMassExorcism) {
        Spell(MassExorcism usable=1)
      }

      #Divine Storm with Divine Crusader.
      if BuffPresent(DivineCrusader) {
        Spell(DivineStorm usable=1)
      }

      #Judgment.
      Spell(Judgment usable=1)

      #Normal Exorcism.
      if Glyph(GlyphMassExorcism no) {
        Spell(Exorcism usable=1)
      }

      #Divine Storm.
      Spell(DivineStorm usable=1)
    }
  }

  #Ranged attacks.
  if target.Exists() and target.IsFriend(no) and target.InRange(CrusaderStrike no) {

    #Judgment when Censure is about to run out.
    if SpellKnown(SealOfTruth) and Stance(1) and BuffPresent(Censure) and BuffExpires(Censure 5) {
      Spell(Judgment usable=1)
    }

    #Light's Hammer with Inquisition.
    if TalentPoints(TalentLightsHammer) and BuffPresent(Inquisition) {
      Spell(LightsHammer usable=1)
    }

    #Execution Sentence with Inquisition.
    if TalentPoints(TalentExecutionSentence) and BuffPresent(Inquisition) {
      Spell(ExecutionSentence usable=1)
    }

    #Hammer of Wrath.
    Spell(HammerOfWrath usable=1)

    #Prevent other abilities when Hammer of Wrath is almost ready.
    if SpellUsable(HammerOfWrath no) or SpellCooldown(HammerOfWrath) > 0.25 {

      #Judgment to build holy power or Censure stacks.
      if HolyPower() < 3 or target.BuffStacks(Censure) < 5 {
        Spell(Judgment usable=1)
      }

      #Normal Exorcism to build holy power.
      if HolyPower() < 3 and Glyph(GlyphMassExorcism no) {
        Spell(Exorcism usable=1)
      }

      #Wrath.
      if BuffPresent(BuffSymbiosis) or BuffPresent(BuffOvergrownLilypad) {
        spell(Symbiosis usable=1)
      }

      #Harsh Words with 5 holy power.
      if HolyPower() >= 5 and Glyph(GlyphHarshWords) {
        Spell(WordOfGlory usable=1)
      }

      #Judgment.
      Spell(Judgment usable=1)

      #Normal Exorcism.
      if Glyph(GlyphMassExorcism no) {
        Spell(Exorcism usable=1)
      }
    }
  }

  #Self buffs and heals.
  if target.IsFriend(no) {

    #Cleanse.
    if BuffPresent(Disease any=1) or BuffPresent(Poison any=1) {
      Spell(Cleanse usable=1 priority=1)
    }

    #Sacred Shield.
    if TalentPoints(TalentSacredShield) and InCombat() {
      Spell(SacredShield usable=1 priority=1)
    }
  }
}

#Offensive Cooldowns.
AddIcon mastery=2 help=cd {

  #Only show during combat.
  if InCombat() {

    #Holy Avenger.
    if TalentPoints(TalentHolyAvenger) {
      Spell(HolyAvenger usable=1)
    }

    #Avenging Wrath.
    Spell(AvengingWrath usable=1)

    #Engineering tinker.
    Item(HandsSlot usable=1)

    #Trinkets.
    Item(Trinket0Slot usable=1)
    Item(Trinket1Slot usable=1)
  }

  #Only show when targeting an enemy.
  if target.Exists() and target.IsFriend(no) {

    #Holy Avenger.
    if TalentPoints(TalentHolyAvenger) {
      Spell(HolyAvenger usable=1)
    }

    #Avenging Wrath.
    Spell(AvengingWrath usable=1)

    #Engineering tinker.
    Item(HandsSlot usable=1)

    #Trinkets.
    Item(Trinket0Slot usable=1)
    Item(Trinket1Slot usable=1)
  }
}
AddIcon mastery=3 help=cd {

  #Only show during combat.
  if InCombat() {

    #Only use offensive cooldowns with Inquisition.
    if SpellKnown(Inquisition no) or BuffPresent(Inquisition 2) {

      #Guardian of Ancient Kings.
      Spell(GuardianOfAncientKingsRetribution usable=1)

      #Holy Avenger without letting it expire before Guardian Of Ancient Kings.
      if TalentPoints(TalentHolyAvenger) and BuffExpires(GuardianOfAncientKingsRetribution 18) {
        Spell(HolyAvenger usable=1)
      }

      #Avenging Wrath without letting it expire before Guardian Of Ancient Kings.
      if TalentPoints(TalentAvengingWrath) or BuffExpires(GuardianOfAncientKingsRetribution 20) {
        Spell(AvengingWrath usable=1)
      }

      #Engineering tinker.
      Item(HandsSlot usable=1)

      #Trinkets.
      Item(Trinket0Slot usable=1)
      Item(Trinket1Slot usable=1)
    }
  }

  #Only show when targeting an enemy.
  if target.Exists() and target.IsFriend(no) {

    #Only use offensive cooldowns with Inquisition.
    if SpellKnown(Inquisition no) or BuffPresent(Inquisition 2) {

      #Guardian of Ancient Kings.
      Spell(GuardianOfAncientKingsRetribution usable=1)

      #Holy Avenger without letting it expire before Guardian Of Ancient Kings.
      if TalentPoints(TalentHolyAvenger) and BuffExpires(GuardianOfAncientKingsRetribution 18) {
        Spell(HolyAvenger usable=1)
      }

      #Avenging Wrath without letting it expire before Guardian Of Ancient Kings.
      if TalentPoints(TalentAvengingWrath) or BuffExpires(GuardianOfAncientKingsRetribution 20) {
        Spell(AvengingWrath usable=1)
      }

      #Engineering tinker.
      Item(HandsSlot usable=1)

      #Trinkets.
      Item(Trinket0Slot usable=1)
      Item(Trinket1Slot usable=1)
    }
  }
}

#Defensive Cooldowns.
AddIcon mastery=2 help=cd {

  #Do not stack defensive cooldowns.
  if BuffExpires(DivineProtection) and BuffExpires(GuardianOfAncientKingsProtection) and BuffExpires(ArdentDefender) and BuffExpires(HolyAvenger) and BuffExpires(DevotionAura) and BuffExpires(BuffBarkskin) and BuffExpires(DivineShield) {

    #Only show during combat.
    if InCombat() {

      #Divine Protection.
      Spell(DivineProtection usable=1)

      #Guardian of Ancient Kings.
      Spell(GuardianOfAncientKingsProtection usable=1)

      #Ardent Defender.
      Spell(ArdentDefender usable=1)

      #Holy Avenger.
      if TalentPoints(TalentHolyAvenger) {
        Spell(HolyAvenger usable=1)
      }

      #Devotion Aura.
      Spell(DevotionAura usable=1)

      #Trinkets.
      Item(Trinket0Slot usable=1)
      Item(Trinket1Slot usable=1)

      #Engineering tinker.
      Item(HandsSlot usable=1)

      #Barkskin.
      if BuffPresent(BuffSymbiosis) or BuffPresent(BuffOvergrownLilypad) {
        Spell(Symbiosis)
      }

      #Divine Shield without Forbearance.
      if BuffExpires(Forbearance) {
        Spell(DivineShield usable=1)
      }
    }

    #Only show when targeting an enemy.
    if target.Exists() and target.IsFriend(no) {

      #Divine Protection.
      Spell(DivineProtection usable=1)

      #Guardian of Ancient Kings.
      Spell(GuardianOfAncientKingsProtection usable=1)

      #Ardent Defender.
      Spell(ArdentDefender usable=1)

      #Holy Avenger.
      if TalentPoints(TalentHolyAvenger) {
        Spell(HolyAvenger usable=1)
      }

      #Devotion Aura.
      Spell(DevotionAura usable=1)

      #Trinkets.
      Item(Trinket0Slot usable=1)
      Item(Trinket1Slot usable=1)

      #Engineering tinker.
      Item(HandsSlot usable=1)

      #Barkskin.
      if BuffPresent(BuffSymbiosis) or BuffPresent(BuffOvergrownLilypad) {
        Spell(Symbiosis)
      }

      #Divine Shield without Forbearance.
      if BuffExpires(Forbearance) {
        Spell(DivineShield usable=1)
      }
    }
  }
}
AddIcon mastery=3 help=cd {

  #Do not stack defensive cooldowns.
  if BuffExpires(DivineProtection) and BuffExpires(HolyAvenger) and BuffExpires(DevotionAura) and BuffExpires(DivineShield) {

    #Only show during combat.
    if InCombat() {

      #Divine Protection.
      Spell(DivineProtection usable=1)

      #Holy Avenger.
      if TalentPoints(TalentHolyAvenger) {
        Spell(HolyAvenger usable=1)
      }

      #Devotion Aura.
      Spell(DevotionAura usable=1)

      #Divine Shield without Forbearance.
      if BuffExpires(Forbearance) {
        Spell(DivineShield usable=1)
      }
    }

    #Only show when targeting an enemy.
    if target.Exists() and target.IsFriend(no) {

      #Divine Protection.
      Spell(DivineProtection usable=1)

      #Holy Avenger.
      if TalentPoints(TalentHolyAvenger) {
        Spell(HolyAvenger usable=1)
      }

      #Devotion Aura.
      Spell(DevotionAura usable=1)

      #Divine Shield without Forbearance.
      if BuffExpires(Forbearance) {
        Spell(DivineShield usable=1)
      }
    }
  }
}



]],
}
